﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using FlowerShop.Models;
namespace FlowerShop.Controllers
{
    public class OrdersController : Controller
    {
        FlowerDBEntities db = new FlowerDBEntities();
        //
        // GET: /Orders/

        public ActionResult Index()
        {
            return View(DataAccessLayer.OrdersDAO.GetAllOrders());
        }

        //
        // GET: /Orders/Details/5

        public ActionResult Details(int id)
        {
          
            return View();
        }

        //
        // GET: /Orders/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Orders/Create

        [HttpPost]
        public ActionResult Create(OrderModels order)
        {
            try
            {
                // TODO: Add insert logic here
                DataAccessLayer.OrdersDAO.InsertOrders(order);
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        
        //
        // GET: /Orders/Edit/5
 
        public ActionResult Edit(int id)
        {
            var od = DataAccessLayer.OrdersDAO.SearchOrders(id);
            OrderModels odm = Mapper.orderToModel(od);
            return View(odm);
        }

        //  
        // POST: /Orders/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, OrderModels odm)
        {
            try
            {
                // TODO: Add update logic here
                DataAccessLayer.OrdersDAO.UpdateOrders(odm);
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Orders/Delete/5
 
        public ActionResult Delete(int id)
        {
            DataAccessLayer.OrdersDAO.DeleteOrders(id);
            return RedirectToAction("Index");
        }

        //
        // POST: /Orders/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
                
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
